#include<ConfigWindow.h>

ConfigWindow::ConfigWindow()
{
    fncPB = new FuncaoPerimetroBonus();
    fncME = new FuncaoMatrizEstatica();
    fncQS = new FuncaoQuantidade();

    lineHeuristica = new QHBoxLayout(this);
    gbHeuristica = new QGroupBox(tr("Evaluation Function"), this);
    lbHeuristica = new QLabel(tr("Select the Evaluation Function that IA should use: "), this);
    cbHeuristica = new QComboBox(this);

    cbHeuristica->addItem(tr("PerimetroBonus"));
    cbHeuristica->addItem(tr("MatrizEstatica"));
    cbHeuristica->addItem(tr("QuantidadeSimples"));

    cbHeuristica->setCurrentIndex(0);

    lineHeuristica->addWidget(lbHeuristica);
    lineHeuristica->addWidget(cbHeuristica);

    gbHeuristica->setLayout(lineHeuristica);

    lineDif = new QHBoxLayout(this);
    gbDif = new QGroupBox(tr("IA Level"), this);
    lbDif = new QLabel(tr("Select the level of AI: "), this);
    cbDif = new QComboBox(this);

    cbDif->addItem(tr("Very Easy"));
    cbDif->addItem(tr("Easy"));
    cbDif->addItem(tr("Medium"));
    cbDif->addItem(tr("Hard"));
    cbDif->addItem(tr("Very Hard"));
    cbDif->setCurrentIndex(2);

    lineDif->addWidget(lbDif);
    lineDif->addWidget(cbDif);

    gbDif->setLayout(lineDif);

    lineTransSpeed = new QHBoxLayout(this);
    gbTS = new QGroupBox(tr("Effect speed"), this);
    lbTS = new QLabel(tr("Select the speed of the IA play effect: "), this);
    cbTS = new QComboBox(this);

    cbTS->addItem(tr("Slow"));
    cbTS->addItem(tr("Medium"));
    cbTS->addItem(tr("Fast"));
    cbTS->setCurrentIndex(1);

    lineTransSpeed->addWidget(lbTS);
    lineTransSpeed->addWidget(cbTS);

    gbTS->setLayout(lineTransSpeed);

    btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
    connect(btnBox, SIGNAL(accepted()), this, SLOT(bntOkPressed()));
    connect(btnBox, SIGNAL(rejected()), this, SLOT(bntCancelPressed()));


    finalLayout = new QVBoxLayout(this);    

    finalLayout->addWidget(gbHeuristica);
    finalLayout->addWidget(gbDif);
    finalLayout->addSpacing(20);
    finalLayout->addWidget(gbTS);
    finalLayout->addSpacing(40);
    finalLayout->addWidget(btnBox);

    setLayout(finalLayout);
    
    setMinimumSize(sizeHint());
    //setFixedSize(800, 750);
    setWindowModality(Qt::ApplicationModal);
    setWindowTitle(tr("Configuration"));
}

void ConfigWindow::bntOkPressed()
{

    if(cbHeuristica->currentIndex() == 1)
        emit updateEvalFunc(fncME);
    else if(cbHeuristica->currentIndex() == 2)
        emit updateEvalFunc(fncQS);
    else emit updateEvalFunc(fncPB);

    switch(cbDif->currentIndex())
    {
        case 0:
            emit updateAILevel(DIFFICULT_VERYEASY);
            break;
        case 1:
            emit updateAILevel(DIFFICULT_EASY);
            break;
        case 2:
            emit updateAILevel(DIFFICULT_MEDIUM);
            break;
        case 3:
            emit updateAILevel(DIFFICULT_HARD);
            break;
        case 4:
            emit updateAILevel(DIFFICULT_VERYHARD);
            break;
        default:
            emit updateAILevel(DIFFICULT_MEDIUM);
    }

    switch(cbTS->currentIndex())
    {
        case 0:
            emit updateTRSpeed(TRSPEED_SLOW);
            break;
        case 1:
            emit updateTRSpeed(TRSPEED_MED);
            break;
        case 2:
            emit updateTRSpeed(TRSPEED_FAST);
            break;
        default:
            emit updateTRSpeed(TRSPEED_MED);
            break;
    }
   
    hide();
}

void ConfigWindow::bntCancelPressed()
{

    hide();

}

void ConfigWindow::setupConfigs()
{
    emit updateEvalFunc(fncPB);
    emit updateAILevel(DIFFICULT_MEDIUM);
    emit updateTRSpeed(TRSPEED_MED);
}

